/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author WinKiQue58
 */
@Entity
@Table(name = "RECORD")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Record.findAll", query = "SELECT r FROM Record r"),
    @NamedQuery(name = "Record.findByIdRecord", query = "SELECT r FROM Record r WHERE r.recordPK.idRecord = :idRecord"),
    @NamedQuery(name = "Record.findByIdPersonalInfo", query = "SELECT r FROM Record r WHERE r.recordPK.idPersonalInfo = :idPersonalInfo"),
    @NamedQuery(name = "Record.findByIdBranchenterprise", query = "SELECT r FROM Record r WHERE r.recordPK.idBranchenterprise = :idBranchenterprise"),
    @NamedQuery(name = "Record.findByIdEnterprise", query = "SELECT r FROM Record r WHERE r.recordPK.idEnterprise = :idEnterprise"),
    @NamedQuery(name = "Record.findByInitdate", query = "SELECT r FROM Record r WHERE r.initdate = :initdate"),
    @NamedQuery(name = "Record.findByEnddate", query = "SELECT r FROM Record r WHERE r.enddate = :enddate")})
public class Record implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected RecordPK recordPK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "INITDATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date initdate;
    @Column(name = "ENDDATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date enddate;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "record", fetch = FetchType.LAZY)
    private List<ProductPreference> productPreferenceList;
    @JoinColumns({
        @JoinColumn(name = "ID_PERSONAL_INFO", referencedColumnName = "ID_PERSONAL_INFO", insertable = false, updatable = false),
        @JoinColumn(name = "ID_BRANCHENTERPRISE", referencedColumnName = "ID_BRANCHENTERPRISE", insertable = false, updatable = false),
        @JoinColumn(name = "ID_ENTERPRISE", referencedColumnName = "ID_ENTERPRISE", insertable = false, updatable = false)})
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private PersonalInfo personalInfo;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "record", fetch = FetchType.LAZY)
    private List<ServicePreference> servicePreferenceList;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "record", fetch = FetchType.LAZY)
    private Commission commission;

    public Record() {
    }

    public Record(RecordPK recordPK) {
        this.recordPK = recordPK;
    }

    public Record(RecordPK recordPK, Date initdate) {
        this.recordPK = recordPK;
        this.initdate = initdate;
    }

    public Record(BigInteger idRecord, BigInteger idPersonalInfo, BigInteger idBranchenterprise, BigInteger idEnterprise) {
        this.recordPK = new RecordPK(idRecord, idPersonalInfo, idBranchenterprise, idEnterprise);
    }

    public RecordPK getRecordPK() {
        return recordPK;
    }

    public void setRecordPK(RecordPK recordPK) {
        this.recordPK = recordPK;
    }

    public Date getInitdate() {
        return initdate;
    }

    public void setInitdate(Date initdate) {
        this.initdate = initdate;
    }

    public Date getEnddate() {
        return enddate;
    }

    public void setEnddate(Date enddate) {
        this.enddate = enddate;
    }

    @XmlTransient
    public List<ProductPreference> getProductPreferenceList() {
        return productPreferenceList;
    }

    public void setProductPreferenceList(List<ProductPreference> productPreferenceList) {
        this.productPreferenceList = productPreferenceList;
    }

    public PersonalInfo getPersonalInfo() {
        return personalInfo;
    }

    public void setPersonalInfo(PersonalInfo personalInfo) {
        this.personalInfo = personalInfo;
    }

    @XmlTransient
    public List<ServicePreference> getServicePreferenceList() {
        return servicePreferenceList;
    }

    public void setServicePreferenceList(List<ServicePreference> servicePreferenceList) {
        this.servicePreferenceList = servicePreferenceList;
    }

    public Commission getCommission() {
        return commission;
    }

    public void setCommission(Commission commission) {
        this.commission = commission;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (recordPK != null ? recordPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Record)) {
            return false;
        }
        Record other = (Record) object;
        if ((this.recordPK == null && other.recordPK != null) || (this.recordPK != null && !this.recordPK.equals(other.recordPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Record[ recordPK=" + recordPK + " ]";
    }
    
}
